import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import {addItem,deleteItem} from "../api"

export default new Vuex.Store({
  state: {
    list:[]
  },
  mutations: {
    ADD_ITEM(state,data){
      state.list=data
    },
    DELETE_ITEM(state,data){
      state.list=data
    }
  },
  actions: {
    addItem(context,data){
      addItem(data).then(res=>{
        context.commit('ADD_ITEM',res.data.data)
      })
    },
    deleteItem(context,data){
      deleteItem(data).then(res=>{
        context.commit('DELETE_ITEM',res.data.newdata)
      })
    }
  },
  modules: {
  }
})
